package com.aefottt.struggle_star.base;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.aefottt.struggle_star.R;
import com.aefottt.struggle_star.util.StatusBarUtil;

public abstract class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusBar();
        if (getLayoutId() == 0){
            throw new IllegalArgumentException("LayoutId has not been set");
        }
        setContentView(getLayoutId());
        initView();
        initListener();
        initEvent();
    }

    private void setStatusBar(){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            if (isFullScreenMode()){
                StatusBarUtil.transparencyBar(this);
            }else {
                StatusBarUtil.setStatusBarColor(this, getStatusBarColor());
            }

            if (isBlackFontStatusBar()){
                StatusBarUtil.setLightStatusBar(this, true, isFullScreenMode());
            }
        }
    }

    /**
     * 设置布局Id
     * @return LayoutId
     */
    protected abstract int getLayoutId();

    /**
     * 是否全屏默认（透明状态栏），默认否
     */
    protected boolean isFullScreenMode() {
        return false;
    }

    /**
     * 设置状态栏颜色，默认为白色（只有在非全屏模式下生效）
     * @return StatusBar Color
     */
    protected int getStatusBarColor() {
        return R.color.white;
    }

    /**
     * 状态栏字体及图标是否设置为黑色，默认为黑色
     */
    protected boolean isBlackFontStatusBar(){
        return true;
    }

    protected void initView(){}

    protected void initListener(){}

    protected void initEvent(){}

}
